<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<script th:fragment="script">
function processSubmitResult(result, resultMessage) {
// 根据返回结果更新提示信息
            if (result.success) {
                const data = result.data;
                if (data.status == 'FAIL') {
                    resultMessage.textContent = `支付失败！${data.message}。`;
                    resultMessage.style.color = 'red';
                } else if (data.status == 'SUCCESS') {
                    resultMessage.textContent = `支付成功！`;
                    resultMessage.style.color = 'green';
                } else {
                    if (data.ird) {
                        const jsonObj = JSON.parse(data.ird);
                        if (jsonObj.type == 'pageUrl') {
                            location.href = jsonObj.content;
                        } else if (jsonObj.type == 'formContent') {
                            // 如果返回了 HTML 表单，则动态插入并自动提交
                            const formContainer = document.createElement('div');
                            formContainer.innerHTML = jsonObj.content;

                            // 将表单插入到页面中
                            document.body.appendChild(formContainer);

                            // 自动提交表单
                            const form = formContainer.querySelector('form');
                            if (form) {
                                form.submit();
                            } else {
                                resultMessage.textContent = '支付失败：无效的表单数据。';
                                resultMessage.style.color = 'red';
                            }
                        } else {
                            alert('支付处理中:' + data.resultMsg);
                        }
                    }
                }
            } else {
                resultMessage.textContent = `支付请求失败：${result.message || '未知错误'}`;
                resultMessage.style.color = 'red';
            }
}
</script>